// POJ1655 Balancing Act
// 陈锋
#include <cstdio>
#include <vector>
const int MAXN = 20000 + 4;
using namespace std;
int N, MaxS, Centroid;
vector<int> E[MAXN];
int dfs(int u, int fa) {
  int s = 1, max_s = -1;
  for (size_t i = 0; i < E[u].size(); i++) {
    int v = E[u][i];
    if (v == fa) continue;
    int sv = dfs(v, u);
    s += sv, max_s = max(max_s, sv);  // 统计最大的节点数的子节点数
  }
  max_s = max(max_s, N - s);  // 除了子树u之外的其它子树大小
  if (max_s < MaxS || (max_s == MaxS && Centroid > u))
    MaxS = max_s, Centroid = u;
  return s;
}

int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) E[i].clear();
    for (int i = 1, u, v; i < N; i++) {
      scanf("%d %d", &u, &v);
      E[u].push_back(v), E[v].push_back(u);
    }
    MaxS = MAXN, Centroid = 0;
    dfs(1, -1);
    printf("%d %d\n", Centroid, MaxS);
  }
  return 0;
}
/*
算法分析请参考: 《入门经典-第2版》 9.4.2一节 树的重心
*/
// Accepted 125ms 1524kB 882 G++ 2020-12-08 20:57:28 22197148